/*
 * @Author: White
 * @description: 分享 - 工具函数 - 混入
 * @LastEditTime: 2021-07-03 01:15:53
 */

export default {
    methods: {
        // 分享微信朋友圈等  参考https://juejin.cn/post/6844903825589927944
        
        // 分享到QQ好友
        shareToQQ() {
            // 此处分享链接内无法携带图片
            const share = {
                title: "潮牌客APP",
                desc: "潮牌客APP潮牌客APP潮牌客APP潮牌客APP潮牌客APP",
                share_url: "www.baidu.com"
            };
            location.replace(
                "https://connect.qq.com/widget/shareqq/index.html?url=" +
                encodeURIComponent(share.share_url) +
                "&title=" +
                share.title +
                "&desc=" +
                share.desc
            );
        },
        //分享到QQ空间(可用)
        shareToRoom() {
            //自定义内容
            const share = {
                title: "潮牌客APP",
                desc: "潮牌客APP潮牌客APP潮牌客APP潮牌客APP潮牌客APP",
                image_url: ["https://xxx.jpeg"], //传在线图片
                share_url: "https://地址"
            };
            let image_urls = share.image_url.map(function (image) {
                return encodeURIComponent(image);
            });
            //跳转地址
            location.replace(
                "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" +
                encodeURIComponent(share.share_url) +
                "&title=" +
                share.title +
                "&pics=" +
                image_urls.join("|") +
                "&summary=" +
                share.desc
            );
        },
        //分享到微博
        shareToMicroblog() {
            //自定义内容
            const share = {
                title: "潮牌客APP",
                image_url: ["https://xxx.jpeg"],
                share_url: "https://地址"
            };
            //跳转地址
            location.replace(
                "https://service.weibo.com/share/share.php?url=" +
                encodeURIComponent(share.share_url) +
                "&title=" +
                share.title +
                "&pic=" +
                share.image_url +
                "&searchPic=true"
            );
        },
        // 复制链接
        copy() {
            this.copyContent = 'www.baidu.com';//也可以直接写上等于你想要复制的内容
            var input = document.createElement("input"); // 直接构建input
            input.value = this.copyContent; // 设置内容
            console.log(input.value);
            document.body.appendChild(input); // 添加临时实例
            input.select(); // 选择实例内容
            document.execCommand("Copy"); // 执行复制
            document.body.removeChild(input); // 删除临时实例
            this.$toast('复制成功,快去分享吧');
        }
    }
}